<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>登陆后台管理</title>

    <!-- Bootstrap -->
    <link href="./css/bootstrap.min.css" rel="stylesheet">
    <style>
        html, body {
            height: 100%;
        }
        *, *::before, *::after {
            box-sizing: border-box;
        }
        body{
            display: -ms-flexbox;
            display: flex;
            -ms-flex-align: center;
            align-items: center;
            padding-top: 40px;
            padding-bottom: 40px;
            background-color: #f5f5f5;
        }
        .form-login {
            width: 100%;
            max-width: 330px;
            padding: 15px;
            margin: auto;
            text-align: center;
            background-color: white;
        }
        .mt-5{
            margin-top: 3rem !important;
        }
        .mb-3{
            margin-bottom: 1rem !important;
        }
        .font-weight-normal {
            font-weight: 400 !important;
        }
        .title-text {
            color: #337ab7;
        }
        .close, .close:focus {
            position: relative;
            top: -25px;
            left: -10px;
        }
        .close:focus{
            outline: 0;
        }

    </style>
</head>
<body>
    <form id="login-form" class="form-login">
        <img src="./images/admin.svg" alt="logo" class="img-circle" width="72" height="72">
        <h3 class="title-text font-weight-normal">管理员登陆</h3>
        <div class="form-group">
            <input type="text" id="uname" class="form-control" name="username" placeholder="请输入用户名" required autofocus>
            <button type="button" class="close" aria-label="Close" id="clear-uname"><span aria-hidden="true">&times;</span></button>
        </div>
        <div class="form-group">
            <input type="password" id="upwd" class="form-control" name="password" placeholder="请输入密码" required>
            <button type="button" class="close" aria-label="Close" id="clear-upwd"><span aria-hidden="true">&times;</span></button>
        </div>
        <button type="button" class="btn btn-lg btn-primary btn-block" id="btn-login">登陆</button>
        <p class="mt-5 mb-3 text-muted">© 2017-2019</p>
    </form>

    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="./js/jquery-3.4.1.min.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="./js/bootstrap.min.js"></script>
    <!-- 自定义Js-->
    <script>
        $("#clear-uname").click(function () {
            $("#uname").val("").focus();
        });
        $("#clear-upwd").click(function () {
            $("#upwd").val("").focus();
        });
        $("#btn-login").click(function () {
            $.ajax({
                type: "GET",   //提交的方法
                url:"http://localhost:8080/ycumall/api/admin.do?method=login", //提交的地址
                data:$('#login-form').serialize(),// 序列化表单值
                async: false,
                error: function(request) {  //失败的话
                    alert("用户名或密码错误!");
                },
                success: function(data) {  //成功
                    if(data.msg === 200) {
                        window.location.href="index.html";
                    } else {
                        alert("用户名或密码错误!");
                    }
                }
            });
        });

    </script>
</body>
</html>